use counter_bench::{run_atomic, run_mutex, warm_up, N_THREADS, N_TIMES};
use criterion::{criterion_group, criterion_main, Criterion};

fn atomic_bench(c: &mut Criterion) {
    c.bench_function("atomic counter", |b| {
        b.iter(|| run_atomic(N_TIMES, N_THREADS))
    });
}

fn mutex_bench(c: &mut Criterion) {
    c.bench_function("mutex counter", |b| {
        b.iter(|| run_mutex(N_TIMES, N_THREADS))
    });
}

fn benches() -> Criterion {
    let mut crit = Criterion::default()
        .sample_size(10)
        .warm_up_time(std::time::Duration::from_secs(1))
        .measurement_time(std::time::Duration::from_secs(2));
    warm_up();
    crit
}

criterion_group! {
    name = compare;
    config = benches();
    targets = atomic_bench, mutex_bench
}

criterion_main!(compare);